﻿using System;
using System.Collections.Generic;
using System.Text;

//public struct Point
//{
//    public Int32 x;
//    public Int32 y;
//    public Point(Int32 _x,Int32 _y)
//        : this()
//    {
//        x = _x;
//        y = _y;
//    }
//    public Boolean equals(Point p)
//    {
//        return (p.x == x && p.y == y);
//    }
//    override public string ToString()
//    {
//        return x.ToString() + ":" + y.ToString();
//    }
//}

public struct Point
{

    public UInt32 x;
    public UInt32 y;
    public UInt64 z;
    public Point(UInt32 _x, UInt32 _y, UInt64 _z)
    {
        x = _x;
        y = _y;
        z = _z;
    }

    public Boolean equals(Point p)
    {
        return (p.x == x && p.y == y) || (p.z == z);
    }

    public byte QuerySrvId()
    {
        UInt32 high = (UInt32)(z >> 32);
        return (byte)(high >> 28);
    }

    /// <summary>
    /// 对象的类型(ObjType)
    /// </summary>
    public byte QueryType()
    {
        UInt32 high = (UInt32)(z >> 32);
        return (byte)((high >> 20) & 0xFF);
    }

    public UInt32 QuerySubType()
    {
        UInt32 high = (UInt32)(z >> 32);
        return (high & 0xFFFFF);
    }

    /// <summary>
    /// 64位str转换为objID
    /// </summary>
    /// <param name="objId">64位str</param>
    public Point SetObjectID(string objId)
    {
        z = ulong.Parse(objId);
        x = QueryType();
        y = QuerySubType();
        return this;
    }
    /// <summary>
    /// 默认格式转化为对应64为objId
    /// </summary>
    /// <param name="nServerID">服务器</param>
    /// <param name="nObjectId">对象Id</param>
    /// <param name="nSubId">类型</param>
    /// <param name="nIdentity">tag</param>
    /// <returns></returns>
    public Point SetObjectID(int nServerID, int nObjectId, UInt32 nSubId, UInt32 nIdentity)
    {
        y = nIdentity;
        x = (UInt32)(((UInt32)(nServerID & 0x0F) << 28) | ((UInt32)(nObjectId & 0xFF) << 20) | (nSubId & 0xFFFFF));
        z = ((UInt64)x << 32) | (UInt64)(y);
        return this;
    }
    
    /// <summary>
    /// Npc的name转换为64位objID(Npc_10010_4_1)
    /// </summary>
    /// <param name="name">Npc的name</param>
    /// <param name="tag">Npc的tag</param>
    public Point StrNameToObjID(string name,string tag)
    {
        string strObjId = name.Split(new string[] { tag }, StringSplitOptions.RemoveEmptyEntries)[0];
        string[] objIdArr = strObjId.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
        return SetObjectID(1, int.Parse(objIdArr[0]), UInt32.Parse(objIdArr[1]), UInt32.Parse(objIdArr[2]) );
    }


    override public string ToString()
    {
        return z.ToString();//+" "+ x.ToString() + ":" + y.ToString();
    }

}

public struct DataType
{
    public enum Value_Type
    {
        VARTYPE_UNKNOWN,   // 未知类型   
        VARTYPE_BOOL,    // 布尔型
        VARTYPE_INT8,    // 8位整数
        VARTYPE_INT16,    // 16位整数
        VARTYPE_INT32,    // 整型
        VARTYPE_INT64,    // 64位整型   
        VARTYPE_UINT8,    // 8位整数
        VARTYPE_UINT16,    // 16位整数
        VARTYPE_UINT32,    // 整型
        VARTYPE_UINT64,    // 64位整型   
        VARTYPE_FLOAT,    // 浮点型
        VARTYPE_DOUBLE,    // 双精度型   
        VARTYPE_STRING,    // 字符串（以0结尾）
        VARTYPE_WIDESTR,   // 宽字符串（以0结尾）   
        VARTYPE_OBJECT,    // 对象类型（为对象ID）
        VARTYPE_DATETIME,   // 日期类型 
        VARTYPE_POINTER,   // 指针
        VARTYPE_BINARY,    // 二进制数据，需要长度支持   
        VARTYPE_MAX,    // 类型结束符
    }
}